﻿using Business.Core.Annotations;
using Business.Data;
using Common;
using DataModel;
using FangPage.Data;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace ProjectManagerSys
{
    public class DealOtherMerber : Common.BusinessBase
    {
        [Doc("修改任务完成时间", Group = "其他操作")]
        public virtual async Task<dynamic> UpdateTaskRealTime()
        {
            var flag = 0;
            try
            {
                
                using (var con = Data.DB.GetConnection())
                {
                    StringBuilder sql = new StringBuilder();
                    sql.Append("select b.id,b.TASKSTARTTIME,a.CREATETIME from((select * from MANAGER_TASKFLOWLOG where NEWCONTENT='已完成' and  TASKID in (select ID from MANAGER_TASK where TASKSTATUS =2 and REALTIME is null))a ");
                    sql.Append("left join ");
                    sql.Append("(select * from MANAGER_TASK where TASKSTATUS = 2 and REALTIME is null) b ");
                    sql.Append("on a.taskid = b.id) "); 
                    var list = DbHelper.ExcuteTable(sql.ToString());
                    foreach (DataRow item in list.Rows)
                    {
                        decimal total = (decimal)new TaskMerber().CalculationWorkHour((DateTime)item["taskstarttime"], (DateTime)item["createtime"]);
                        string sql2 = string.Format("update MANAGER_TASK set REALTIME={0},CALREALNAME='{0}' where id='{1}'", total, item["id"]);
                        con.ExecuteNonQuery(sql2);
                    }
                    
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }

            //入库的用户
            return JsonConvert.SerializeObject(flag);
        }
    }
}
